package com.vr.core.system.config;

import cn.hutool.db.ds.pooled.DbConfig;
import com.vr.core.system.interception.DynamicDataSourceInterception;
import com.vr.core.system.interception.TokenInterception;
import lombok.AllArgsConstructor;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Description TODO
 * @Author kenson
 * @Date 2024/12/11 9:44
 */

@Configuration
@AllArgsConstructor
public class JavaBeanConfiguration {

    private final TokenInterception tokenInterception;
    private final DynamicDataSourceInterception dynamicDataSourceInterception;

    @Bean
    public WebMvcConfigurer webMvcConfigurer(){
        return new WebMvcConfigurer() {
            @Override
            public void addCorsMappings(CorsRegistry registry) {
                registry.addMapping("/**")
                        .allowedOriginPatterns("*")
                        .allowedMethods("GET", "POST", "PUT", "DELETE")
                        .allowedHeaders("*")
                        .allowCredentials(true)
                        .maxAge(3600);
            }

            @Override
            public void addInterceptors(InterceptorRegistry registry) {

                registry.addInterceptor(tokenInterception).addPathPatterns("/**").excludePathPatterns("/login/userCredentials");
                registry.addInterceptor(dynamicDataSourceInterception).addPathPatterns("/**").excludePathPatterns("/login/userCredentials");


            }
        };

    }


}
